from redmine.common.base.config_operate import ReadConfig
from redmine.common.redmine_common import MyRedmine

config = ReadConfig()
project_id = config.ALARM_PROJECT
redmine = MyRedmine(config.REDMINE_URL, config.REDMINE_KEY).redmine

# 取issue 根据状态进行判断
issues = redmine.issue.filter(project_name='实时开发', status_id='open®', offset=0, limit=100)
for issue in issues:
    # 获取当前issue 的id编号
    print(issue.id)
    # 获取当前BUG编号
    # 获取bug单标题
    print(issue.subject)
    # 获取bug单的提单人
    print(issue.author)
    # 获取issue创建时间
    # print(issue.created_on)
    # 获取更新时间
    # print(issue.updated_on)
    #遍历追加评论（BUG流转过程）
    # myissue = redmine.issue.get(issue.id, include=['children', 'journals', 'watchers'])
    # for journal in myissue.journals:
    #     # 获取评论人
    #     print(journal.user.name)
    #     # 获取评论时间
    #     print(journal.created_on)
# for issue in issues:
#         history = issue.journals
#         history = sorted(history, key=lambda his: his.created_on,reverse=True)
#         create_on = None
#         for his in history:
#             details = his.details
#             for detail in details:
#                 if(detail["name"] == 'status_id' and detail["new_value"] == '3'):
#                     create_on = his.created_on
#                     break
#             if create_on is not None:
#                 break
#         date = datetime.datetime.now() - datetime.timedelta(hours=hourdif)
#         if(create_on is not None):
#             if(create_on>date):
#                 recent_issues.append(issue)
#     return recent_issues
